package com.rayinhz.bet.controller;

import com.rayinhz.bet.domain.UserDO;
import com.rayinhz.bet.mapper.UserMapper;
import com.rayinhz.bet.response.DataResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * BaseController.java created at 2017年8月8日 下午1:11:20
 *
 * @author Ray [email:rayinhangzhou@hotmail.com]
 * Revision History
 * Date            Programmer                   Notes
 * ----------------------------------------------------------
 **/

@Slf4j
@RestController
@Api(value = "/rest", description = "公用接口")
public class PubController {
    @Autowired
    private UserMapper userMapper;

    @RequestMapping("/sayHello")
    @ApiOperation(value = "sayHello", httpMethod = "GET")
    public String sayHello(@RequestParam String name) {
        return "hello:" + name;
    }

    @RequestMapping(value = "/user", method = RequestMethod.GET)
    @ApiOperation(value = "获取用户")
    public UserDO user(@RequestParam String account) {
        log.info("message logback------->");
        return userMapper.getUserByAccount(account);
    }

    @RequestMapping("/createUser")
    @ApiOperation(value = "创建用户", notes = "根据User对象创建用户", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "用户ID", required = true, dataType = "Long", paramType = "form"),
            @ApiImplicitParam(name = "name", value = "用户名", required = true, dataType = "String", paramType = "form"),
            @ApiImplicitParam(name = "age", value = "年龄", required = true, dataType = "String", paramType = "form")
    })
    public DataResult createUser(@RequestParam String openId,
                                 @RequestParam String nickName,
                                 @RequestParam String avatarUrl,
                                 @RequestParam String gender) {
        return DataResult.success(null);
    }

}
